package cn.itsy.dao.job;

import cn.itsy.pojo.Emp;
import cn.itsy.pojo.Job;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: MisterGay
 * @date: 2019-05-28 9:12
 */
@Repository(value = "jobDaoimpl")
public class JobDaoimpl implements JobDao {

    @Resource(name = "jdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    @Override
    public void deleteJobById(String sql, Integer dept_id) {
        this.jdbcTemplate.update(sql, dept_id);
    }

    @Override
    public void insertJob(String sql, Job job) {
        this.jdbcTemplate.update(sql, job.getId(), job.getNumber(), job.getName(),
                job.getDuctId(), job.getDeptId(), job.getWren(), job.getWinfo());
    }

    @Override
    public List<Job> queryJobAll(String sql) {
        List<Job> query = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<Job>(Job.class));
        return query;
    }

    @Override
    public void updateJobById(String sql, Job job) {
        this.jdbcTemplate.update(sql, job.getId(), job.getNumber(), job.getName(),
                job.getDuctId(), job.getDeptId(), job.getWren(), job.getWinfo(), job.getId());
    }

    @Override
    public void updateJobById(String sql, Job job, Integer checkId) {
        this.jdbcTemplate.update(sql, job.getId(), checkId);
    }

    @Override
    public void updateEmpByJobId(String sql, Job job, Integer checkId) {
        this.jdbcTemplate.update(sql, job.getId(), checkId);
    }

    @Override
    public List<Emp> queryEmpById(String sql, Job job) {
        List<Emp> query = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<Emp>(Emp.class), job.getId());
        return query;
    }

    @Override
    public void deleteJobById(String sql, Job job) {
        this.jdbcTemplate.update(sql, job.getId());
    }
}
